package com.yanqu.road.server.cmd.activity.worldcup;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WorldCupProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.worldcup.WorldCupModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.climbtower.ClimbTowerMgr;
import com.yanqu.road.server.manger.activity.worldcup.WorldCupMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_WORLDCUP_RECRUIT, desc = "招募")
public class WorldCupRecruitCmd extends AbstractCommand {

    private WorldCupProto.WorldCupRecruitReqMsg reqMsg;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = WorldCupProto.WorldCupRecruitReqMsg.parseFrom(packet.getBytes());
        if (reqMsg.getNum() <= 0 || reqMsg.getNum() > 10) {
            return false;
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        // 没有活动
        if (!ActivityMgr.activityInTime(WorldCupMgr.getActivityInfo()) || WorldCupMgr.getConfig() == null) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        ret = player.getModule(WorldCupModule.class).recruitBaller(reqMsg.getNum());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            player.sendPacket(Protocol.U_WORLDCUP_RECRUIT, WorldCupProto.WorldCupRecruitRespMsg.newBuilder().setRet(ret).setRewards(""));
        }
    }
}
